<?php

namespace App\Http\Controllers\Api\User;

use Illuminate\Http\Request;
use App\Http\Requests\Api\ApiRequest;
use App\Http\Controllers\Controller;
use App\Repos\InviteRepo;
use App\Repos\FavoriteRepo;

class FavoriteController extends Controller
{
   // 我的收藏列表
   public function index(ApiRequest $request)
   {
   	$rs['status'] = true;
   	$where['user_id'] = $request->user_id;
   	$list = FavoriteRepo::getPages($where,10);
   	$rs['data'] = $list;
   	return response()->json($rs);
   }

   // 添加收藏
    public function save(ApiRequest $request)
    {
    	$data = $request->pure();
    	$data['user_id']  = $request->user_id;
    	$data['favorite_user_id'] = $request->favorite_user_id;
    	FavoriteRepo::save($data);
    	//$rs['data']   = $data;
   		$rs['status'] = true;
   		return response()->json($rs);
    }

    public function cancle(ApiRequest $request)
    {
    	$rs['status']             = false;
    	$where['user_id']          = $request->user_id;
    	$where['favorite_user_id'] = $request->favorite_user_id;
    	$flag = FavoriteRepo::delete($where);
    	if($flag) {
    		$rs['status'] = true;	
    	}
    	
   		return response()->json($rs);
    }

   
}
